<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

</body>
<script>
//try-catch
//处理错误方式1-通过try-catch处理语法错误
/*
try{
  let obj = JSON.parse("{username: 'zs'}")
}catch(e){
    console.log(e)
}
*/

// try {
//   throw new Error('错误了')//主动抛错
// } catch (error) {
//   console.log(error)

// }
/*==============================⭐  ==============================*/
function request(){
  return new Promise((resolve,reject)=>{
    // 触发catch,法一：
    reject(new Error('错误了'))
    // 触发catch,法二：
    throw new Error('错误了')
    // 触发catch,法三：
    resolve(new Promise((resolve,reject)=>{
      reject(new Error('错误了'))
    }))
    // 法三：简写👇
    resolve(Promise.reject(new Error('错误了')))
  })
}
async function fn(){
  try {
    await request()
  } catch (error) {
    console.log(error)

  }
}
</script>
</html>
